package com.larry.spring;

import com.larry.spring.bean.Cat;
import com.larry.spring.bean.Person;
import com.larry.spring.config.MainConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @ProjectName spring
 * @Author larry
 * @Date 21:14 2021/9/2
 * @Description TODO
 **/
public class AnnotationTest {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfig.class);
		//Person bean = context.getBean(Person.class);
		//System.out.println(bean);

		//String[] names = context.getBeanDefinitionNames();
		//System.out.println(names);
		//for (String name : names) {
		//	System.out.println(name);
		//}

		//Cat bean = context.getBean(Cat.class);
		//Cat bean2 = context.getBean(Cat.class);
		//System.out.println(bean == bean2);	//FALSE

		Person bean1 = context.getBean(Person.class);
		Person bean2 = context.getBean(Person.class);
		Cat cat = bean1.getCat();
		Cat cat2 = bean2.getCat();
		//person为单实例，第一次创建person的时候容器初始化的cat
		System.out.println(cat == cat2);	//true

	}

}
